#!/bin/bash

set -e
set -x

# https://downloads.apache.org/kafka/3.9.0/kafka_2.13-3.9.0.tgz
bypy download kafka_2.13-3.9.0.tgz
tar xf kafka_2.13-3.9.0.tgz -C /opt/
mv /opt/kafka_2.13-3.9.0 /opt/kafka
source /etc/profile
echo "JAVA=$JAVA_HOME" >> /opt/kafka/env
echo "PATH=$PATH" >> /opt/kafka/env

KAFKA_CLUSTER_ID="$(/opt/kafka/bin/kafka-storage.sh random-uuid)"
/opt/kafka/bin/kafka-storage.sh format -t $KAFKA_CLUSTER_ID -c /opt/kafka/config/kraft/server.properties
# /opt/kafka/bin/kafka-server-start.sh /opt/kafka/config/kraft/server.properties
cp kafka.service /usr/lib/systemd/system/
systemctl daemon-reload
systemctl enable --now kafka

# /opt/kafka/bin/kafka-topics.sh --create --topic tophant.test --bootstrap-server localhost:9092 --if-not-exists

set +x
set +e